#include "../no_xiang_tu0.h"
struct node{
    int wei;
    int index;
};
int main() {
    int numVertices ;
    int src,dest,weight;
    int m;
    cin>>numVertices>>m;
    WeightedGraph_quan graph(numVertices);
    for(int i=0;i<m;i++){
        cin>>src>>dest>>weight;
        graph.addEdge(src-1,dest-1,weight);
    }
    vector<node> a;
    for(int i=0;i<numVertices;i++){
        int max1=0;
        vector<int> dist;
        graph.Dijkstra(i,dist);
        for(int j=0;j<numVertices;j++&&j!=i){
            if(dist[j]>=9999){cout<<0;
                return 0;}
            max1 = max(max1,dist[j]);
        }
        node n{};
        n.index=i+1;
        n.wei = max1;
        a.push_back(n);
    }
    node min_node{};
    min_node.wei=999;
    for(int i=0;i<numVertices;i++){
        if(a[i].wei<min_node.wei){
            min_node.wei=a[i].wei;
            min_node.index=a[i].index;
        }
    }
    cout<<min_node.index<<" "<<min_node.wei;
    return 0;
}